<template>
  <div class="icons">
    <swiper :options="swiperOption" v-if="pages.length">
      <swiper-slide v-for="(page,index) of pages" :key="index">
        <div class="icon" v-for="item of page" :key="item.id">
          <img class="icon-img" :src="item.iconUrl"/>
          <span class="icon-text">{{ item.iconText }}</span>
        </div>
      </swiper-slide>
      <div v-if="pages.length > 1" class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  props: {
    iconList: Array
  },
  data: function () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination'
      }
    }
  },
  computed: {
    pages: function () {
      let pages = []
      this.iconList.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>

@import '~styles/varibles.styl'
@import '~styles/mixins.styl'

.icons {
  width: 100%;
}

.icons >>> .swiper-container {
  height: 0;
  padding-bottom: 54%;
}

.icons >>> .swiper-pagination-bullet-active {
  background: #00bcd4 !important;
  width: 0.12rem !important;
  height: 0.12rem !important;
}

.icons >>> .swiper-pagination-bullet {
  width: 0.12rem;
  height: 0.12rem;
}

.icon {
  padding-top: 0.1rem;
  width: 25%;
  float: left;
  padding-bottom: 25%;
  height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.icon-img {
  width: 1.1rem;
  height: 1.1rem;
}

.icon-text {
  color: #212121;
  font-size: 0.28rem;
  margin-top: 0.1rem;
}
</style>
